package com.loongtech.bi.action.newsystem;

import com.loongtech.bi.action.authManagement.ResultData;
import com.loongtech.bi.entity.POJO.Page;
import com.loongtech.bi.entity.system.EntitySystemLog;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.Session;
import com.loongtech.core.util.RetCode;
import com.loongtech.core.util.Time;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Author: yuri
 * Description: 日志管理
 * Date: 17:33 2017/5/22
 */
@RestController
@Scope("prototype")
@RequestMapping("/syslog")
public class SysLogManageAction {
	@Resource
	private Session session;
	@Resource
	private SysLogManager sysLogManager;

    /**
     * 查询
     */
    @RequestMapping(value = "list.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultData<?> searchByCriteria(@RequestParam Integer curPage, @RequestParam Integer pageSize,
                                          @RequestParam(value = "dateStart", required = false) String dateStart, @RequestParam (value = "dateEnd", required = false) String dateEnd,
                                          @RequestParam(value = "operator", required = false) String operator,  @RequestParam(value = "gameId", required = false) String gameId, @RequestParam(value = "page", required = false) String page) {
        Date start;
        Date end;
        if (dateStart == null) {
            start = new Date(Time.getBeginningOfDay(Time.currentTime()));
        } else {
            start = Time.formatDate(dateStart, "yyyy-MM-dd HH:mm:ss");
        }
        if (dateEnd == null) {
            end = new Date(Time.getEndOfDay(Time.currentTime()));
        } else {
            end = Time.formatDate(dateEnd, "yyyy-MM-dd HH:mm:ss");
        }
        Page<List<EntitySystemLog>> list;
        try {
            list = sysLogManager.queryByPage(curPage, pageSize, start, end, operator, gameId, page);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultData.otherException();
        }
        return new ResultData<>(RetCode.eSuccess.getErrorcode(), list);
    }
}
